package editor.main;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

import editor.modelo.Floor;

public class FloorTableModel extends AbstractTableModel {

	private static final long serialVersionUID = 1L;
	private  ArrayList<Floor> pisos;
	private ArrayList<Boolean> enabled;
	private ArrayList<Boolean> enabled2;


	public void setPisos(ArrayList<Floor> pisos){
			this.pisos = pisos;
			this.enabled = new ArrayList<Boolean>(pisos.size());
			this.enabled2 = new ArrayList<Boolean>(pisos.size());
			for (int i = 0; i < pisos.size(); i++) {
				enabled.add(false);
				enabled2.add(false);
			}
			fireTableDataChanged();
	}
	public ArrayList<Floor> getPisos(){
		return pisos;
	}
	
	public void addPiso(Floor piso){
		if(pisos == null){
			pisos = new ArrayList<Floor>();
		//	pisos.add(piso);
			enabled = new ArrayList<Boolean>();
			enabled2 = new ArrayList<Boolean>();
			//enabled.add(true);
		}
		enabled.add(true);
		enabled2.add(true);
		pisos.add(piso);
		fireTableDataChanged();
		
	}
	
	public Floor getFloor(int row){
		return pisos.get(row);
	}
	@Override
	public boolean isCellEditable(int row, int col)
	{ return col==1 || col==2; }

	@Override
	public void setValueAt(Object value, int row, int col) {
		if(pisos == null)return;
		if(col == 1)
			enabled.set(row, (Boolean)value);
		else if (col == 2)
			enabled2.set(row, (Boolean)value);
		
		fireTableCellUpdated(row, col);
	}

	@Override
	public int getRowCount() {
		if(pisos == null)return 0;
		return pisos.size();

	}

	@Override
	public int getColumnCount() {
		return 4;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		switch (columnIndex){
		case(0): return pisos.get(rowIndex).getFloorName();
		case(1): return enabled.get(rowIndex);
		case(2): return enabled2.get(rowIndex);
		case(3): return pisos.get(rowIndex).getLevel();	
		} 
		return null;
	}
	@Override 
	public Class<?> getColumnClass(int columnIndex) {
		switch (columnIndex){
		case(0): return String.class;
		case(1): return Boolean.class;
		case(2): return Boolean.class;
		case(3): return Integer.class;	
		} 
		return Object.class;
	}
	@Override
	public String getColumnName(int column) {
		switch (column){
		case(0): return "Nombre";
		case(1): return "Vr";
		case(2): return "Dx";
		case(3): return "Lev";	
		} 
		return "*";
	}

}
